import subprocess
fp=open("out.txt","+a",encoding = "utf-8")
for i in range (1,5):
    str="ping -c 1 192.168.0.{}".format(i)
    a=subprocess.run("ping -c 1 192.168.0.{}".format(i),shell=True)
    #print(str)
    a1=a.returncode
    print(a1)
    if a1 == 0:
        fp.write(str+"已被使用"+'\n')
fp.close()


